1 % Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite
3 {\ttfamily \raggedright {
5 \mbox{}\textbf{\textcolor{Blue
}{struct
}}\ point
\textcolor{Red
}{\
{} \\
6 \mbox{}\ \
\textcolor{ForestGreen
}{double
}\ x
\textcolor{BrickRed
}{,
}y
\textcolor{BrickRed
}{;
} \\
7 \mbox{}\textcolor{Red
}{\
}}\textcolor{BrickRed
}{;
} \\
9 \mbox{}\textbf{\textcolor{Blue
}{inline
}}\
\textcolor{ForestGreen
}{double
}\
\textbf{\textcolor{Black
}{dist
}}\textcolor{BrickRed
}{(
}\textbf{\textcolor{Blue
}{const
}}\ point\
\textcolor{BrickRed
}{\&
}a
\textcolor{BrickRed
}{,
}\
\textbf{\textcolor{Blue
}{const
}}\ point\
\textcolor{BrickRed
}{\&
}b
\textcolor{BrickRed
}{)
}\textcolor{Red
}{\
{} \\
10 \mbox{}\ \
\textbf{\textcolor{Blue
}{return
}}\
\textbf{\textcolor{Black
}{sqrt
}}\textcolor{BrickRed
}{((
}a
\textcolor{BrickRed
}{.
}x
\textcolor{BrickRed
}{-
}b
\textcolor{BrickRed
}{.
}x
\textcolor{BrickRed
}{)*(
}a
\textcolor{BrickRed
}{.
}x
\textcolor{BrickRed
}{-
}b
\textcolor{BrickRed
}{.
}x
\textcolor{BrickRed
}{)
}\
\textcolor{BrickRed
}{+
}\
\textcolor{BrickRed
}{(
}a
\textcolor{BrickRed
}{.
}y
\textcolor{BrickRed
}{-
}b
\textcolor{BrickRed
}{.
}y
\textcolor{BrickRed
}{)*(
}a
\textcolor{BrickRed
}{.
}y
\textcolor{BrickRed
}{-
}b
\textcolor{BrickRed
}{.
}y
\textcolor{BrickRed
}{));
} \\
11 \mbox{}\textcolor{Red
}{\
}} \\
13 \mbox{}\textbf{\textcolor{Blue
}{inline
}}\
\textcolor{ForestGreen
}{double
}\
\textbf{\textcolor{Black
}{distsqr
}}\textcolor{BrickRed
}{(
}\textbf{\textcolor{Blue
}{const
}}\ point\
\textcolor{BrickRed
}{\&
}a
\textcolor{BrickRed
}{,
}\
\textbf{\textcolor{Blue
}{const
}}\ point\
\textcolor{BrickRed
}{\&
}b
\textcolor{BrickRed
}{)
}\textcolor{Red
}{\
{} \\
14 \mbox{}\ \
\textbf{\textcolor{Blue
}{return
}}\
\textcolor{BrickRed
}{(
}a
\textcolor{BrickRed
}{.
}x
\textcolor{BrickRed
}{-
}b
\textcolor{BrickRed
}{.
}x
\textcolor{BrickRed
}{)*(
}a
\textcolor{BrickRed
}{.
}x
\textcolor{BrickRed
}{-
}b
\textcolor{BrickRed
}{.
}x
\textcolor{BrickRed
}{)
}\
\textcolor{BrickRed
}{+
}\
\textcolor{BrickRed
}{(
}a
\textcolor{BrickRed
}{.
}y
\textcolor{BrickRed
}{-
}b
\textcolor{BrickRed
}{.
}y
\textcolor{BrickRed
}{)*(
}a
\textcolor{BrickRed
}{.
}y
\textcolor{BrickRed
}{-
}b
\textcolor{BrickRed
}{.
}y
\textcolor{BrickRed
}{);
} \\
15 \mbox{}\textcolor{Red
}{\
}} \\
17 \mbox{}\textit{\textcolor{Brown
}{/*
}} \\
18 \mbox{}\textit{\textcolor{Brown
}{\ \ Returns\ the\ closest\ distance\ between\ point\ pnt\ and\ the\ segment\ that\ goes\ from\ point\ a\ to\ b
}} \\
19 \mbox{}\textit{\textcolor{Brown
}{\ \ Idea\ by:\
}}\underline{\texttt{\textcolor{Blue
}{http://local.wasp.uwa.edu.au/
}}}\textit{\textcolor{Brown
}{\textasciitilde{}pbourke/geometry/pointline/
}} \\
20 \mbox{}\textit{\textcolor{Brown
}{\ */
}} \\
21 \mbox{}\textcolor{ForestGreen
}{double
}\
\textbf{\textcolor{Black
}{distance$
\_$point$
\_$to$
\_$segment
}}\textcolor{BrickRed
}{(
}\textbf{\textcolor{Blue
}{const
}}\ point\
\textcolor{BrickRed
}{\&
}a
\textcolor{BrickRed
}{,
}\
\textbf{\textcolor{Blue
}{const
}}\ point\
\textcolor{BrickRed
}{\&
}b
\textcolor{BrickRed
}{,
}\
\textbf{\textcolor{Blue
}{const
}}\ point\
\textcolor{BrickRed
}{\&
}pnt
\textcolor{BrickRed
}{)
}\textcolor{Red
}{\
{} \\
22 \mbox{}\ \
\textcolor{ForestGreen
}{double
}\ u\
\textcolor{BrickRed
}{=
}\
\textcolor{BrickRed
}{((
}pnt
\textcolor{BrickRed
}{.
}x\
\textcolor{BrickRed
}{-
}\ a
\textcolor{BrickRed
}{.
}x
\textcolor{BrickRed
}{)*(
}b
\textcolor{BrickRed
}{.
}x\
\textcolor{BrickRed
}{-
}\ a
\textcolor{BrickRed
}{.
}x
\textcolor{BrickRed
}{)
}\
\textcolor{BrickRed
}{+
}\
\textcolor{BrickRed
}{(
}pnt
\textcolor{BrickRed
}{.
}y\
\textcolor{BrickRed
}{-
}\ a
\textcolor{BrickRed
}{.
}y
\textcolor{BrickRed
}{)*(
}b
\textcolor{BrickRed
}{.
}y\
\textcolor{BrickRed
}{-
}\ a
\textcolor{BrickRed
}{.
}y
\textcolor{BrickRed
}{))
}\
\textcolor{BrickRed
}{/
}\
\textbf{\textcolor{Black
}{distsqr
}}\textcolor{BrickRed
}{(
}a
\textcolor{BrickRed
}{,
}\ b
\textcolor{BrickRed
}{);
} \\
23 \mbox{}\ \ point\ intersection
\textcolor{BrickRed
}{;
} \\
24 \mbox{}\ \ intersection
\textcolor{BrickRed
}{.
}x\
\textcolor{BrickRed
}{=
}\ a
\textcolor{BrickRed
}{.
}x\
\textcolor{BrickRed
}{+
}\ u
\textcolor{BrickRed
}{*(
}b
\textcolor{BrickRed
}{.
}x\
\textcolor{BrickRed
}{-
}\ a
\textcolor{BrickRed
}{.
}x
\textcolor{BrickRed
}{);
} \\
25 \mbox{}\ \ intersection
\textcolor{BrickRed
}{.
}y\
\textcolor{BrickRed
}{=
}\ a
\textcolor{BrickRed
}{.
}y\
\textcolor{BrickRed
}{+
}\ u
\textcolor{BrickRed
}{*(
}b
\textcolor{BrickRed
}{.
}y\
\textcolor{BrickRed
}{-
}\ a
\textcolor{BrickRed
}{.
}y
\textcolor{BrickRed
}{);
} \\
26 \mbox{}\ \
\textbf{\textcolor{Blue
}{if
}}\
\textcolor{BrickRed
}{(
}u\
\textcolor{BrickRed
}{$<$
}\
\textcolor{Purple
}{0.0}\
\textcolor{BrickRed
}{$|$$|$
}\ u\
\textcolor{BrickRed
}{$>$
}\
\textcolor{Purple
}{1.0}\textcolor{BrickRed
}{)
}\textcolor{Red
}{\
{} \\
27 \mbox{}\ \ \ \
\textbf{\textcolor{Blue
}{return
}}\
\textbf{\textcolor{Black
}{min
}}\textcolor{BrickRed
}{(
}\textbf{\textcolor{Black
}{dist
}}\textcolor{BrickRed
}{(
}a
\textcolor{BrickRed
}{,
}\ pnt
\textcolor{BrickRed
}{),
}\
\textbf{\textcolor{Black
}{dist
}}\textcolor{BrickRed
}{(
}b
\textcolor{BrickRed
}{,
}\ pnt
\textcolor{BrickRed
}{));
} \\
28 \mbox{}\ \
\textcolor{Red
}{\
}} \\
29 \mbox{}\ \
\textbf{\textcolor{Blue
}{return
}}\
\textbf{\textcolor{Black
}{dist
}}\textcolor{BrickRed
}{(
}pnt
\textcolor{BrickRed
}{,
}\ intersection
\textcolor{BrickRed
}{);
} \\
30 \mbox{}\textcolor{Red
}{\
}} \\
32 } \normalfont\normalsize